/*
 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>

/* WARNING: This code does no error checking whatsoever. */

int main(int argc, char **argv)
{
    struct winsize x = { 0 };
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &x);

    FILE *f = fopen(argv[1], "w");
    fprintf(f, "#ifndef _TERMINAL_TERMINAL_H_\n"
            "#define _TERMINAL_TERMINAL_H_\n"
            "\n"
            "/* THIS FILE IS AUTOGENERATED. DO NOT EDIT. */\n"
            "\n"
            "#define TERMINAL_WIDTH %d\n"
            "#define TERMINAL_HEIGHT %d\n"
            "\n"
            "#endif /* !_TERMINAL_TERMINAL_H_ */\n",
            x.ws_col, x.ws_row);
    fclose(f);
    return 0;
}
